package com.efounder.adapter;

import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.efounder.bean.MallSelectionPayMultipleBean;
import com.efounder.chat.utils.LXGlideImageLoader;
import com.efounder.mobilemall.R;
import com.efounder.utils.Utils;
import com.utilcode.util.ConvertUtils;

import java.util.List;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2018/9/19 9:32
 * @desc :选择支付界面 多布局的adapter
 * @version: 1.0
 */
public class MallSelectionPayMultiAdapter extends BaseMultiItemQuickAdapter<MallSelectionPayMultipleBean, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MallSelectionPayMultiAdapter(List<MallSelectionPayMultipleBean> data) {
        super(data);
        //币的item
        addItemType(MallSelectionPayMultipleBean.PAY_WAY_ITEM, R.layout.mall_recycler_item_selection_pay);
        //中间文本item
        addItemType(MallSelectionPayMultipleBean.OTHER_RECHARGE_WAY_TEXT, R.layout.mall_recycler_item_header_selection_pay);
        //微信  支付宝的item
        addItemType(MallSelectionPayMultipleBean.OTHER_RECHARGE_WAY_ITEM,R.layout.mall_recycler_item_other_selection_pay);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final MallSelectionPayMultipleBean item) {

        switch (helper.getItemViewType()) {
            case MallSelectionPayMultipleBean.PAY_WAY_ITEM:
                //title
                helper.setText(R.id.tv_title,String.format(mContext.getString(R.string.mall_selection_pay_item_pay_way)
                        ,item.getSelectionPay().getTitle(),item.getSelectionPay().getSurplusNum()));

                //图片
                LXGlideImageLoader.getInstance().displayImage(mContext, (ImageView) helper.getView(R.id.iv_icon)
                        ,item.getSelectionPay().getTokenIcon());
                //点击checkBox事件，切换item的选择事件
                ImageView ivSelectionPay = helper.getView(R.id.iv_selection_pay);
                final boolean isSelectionPayWay = item.getSelectionPay().isSelectPayWay();

                if(isSelectionPayWay){
                    ivSelectionPay.setVisibility(View.VISIBLE);
                }else {
                    ivSelectionPay.setVisibility(View.GONE);
                }
                //控制去充值文本的显示隐藏
                if(item.getSelectionPay().isPay()){
                    helper.setText(R.id.tv_pay_status,Utils.matcherSearchTextSize(mContext.getResources().getColor(R.color.op_orange_color)
                            , ConvertUtils.dp2px(13), item.getSelectionPay().getPayStatusHint()
                            , new String[]{item.getSelectionPay().getTokenAmount()}));
                    helper.setVisible(R.id.tv_go_recharge,false);
                }else {
                    helper.setText(R.id.tv_pay_status,item.getSelectionPay().getPayStatusHint());
                    helper.setVisible(R.id.tv_go_recharge,true);
                }
                //去充值添加点击事件
                helper.addOnClickListener(R.id.tv_go_recharge);
                break;
            case MallSelectionPayMultipleBean.OTHER_RECHARGE_WAY_TEXT:
                helper.setText(R.id.tv_header_title,item.getSelectionPay().getTitle());
                break;
            case MallSelectionPayMultipleBean.OTHER_RECHARGE_WAY_ITEM:
                helper.setText(R.id.tv_title,item.getSelectionPay().getTitle());
                //图片
                helper.setImageResource(R.id.iv_icon,item.getSelectionPay().getImageRs());
                ImageView ivSelectionPay1 = helper.getView(R.id.iv_selection_pay);
                final boolean isSelectionPayWay1 = item.getSelectionPay().isSelectPayWay();
                if(isSelectionPayWay1){
                    ivSelectionPay1.setVisibility(View.VISIBLE);
                }else {
                    ivSelectionPay1.setVisibility(View.GONE);
                }
                break;
                default:
        }
    }
}
